package com.prime.tutorial.moviestore.dao;


import com.prime.tutorial.moviestore.domain.Model;
import com.prime.tutorial.moviestore.domain.ModelType;
import org.springframework.stereotype.Repository;

import javax.persistence.Query;
import java.util.List;

@Repository
public class ModelDAOWithJPA extends GenericDAOWithJPA<Model, Long> implements ModelDAO {

    //	@SuppressWarnings("unchecked")
    public List<Model> findByType(String type) {
        Query query = entityManager.createQuery("Select distinct m from Model m where m.type = ?1");
        query.setParameter(1, type);
        return query.getResultList();
//		return getJpaTemplate().find("Select m from Groups m where m.name = ?1",name);
    }

    public List<Model> findByModelType(ModelType modelType) {
        Query query = entityManager.createQuery("Select distinct m from Model m inner join m.modelType as mt where mt.id ='"+modelType.getId()+"'");
        return query.getResultList();
    }
}